package quinielaGold.servlets;

import java.io.*;
import java.awt.*;
import java.net.*;
import java.awt.image.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class AdminImprimir implements Printable {

	public AdminImprimir() {

		/* Construct the print request specification.
		* The print data is a Printable object.
		* the request additonally specifies a job name, 2 copies, and
		* landscape orientation of the media.
		*/
		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
		aset.add(OrientationRequested.LANDSCAPE);
		aset.add(new Copies(1));

		/* Create a print job */
		PrinterJob pj = PrinterJob.getPrinterJob();       
		pj.setPrintable(this);
		/* locate a print service that can handle the request */
		PrintService service =
			PrintServiceLookup.lookupDefaultPrintService();

		if (service != null){
			System.out.println("selected printer " + service.getName());
			try {
				pj.setPrintService(service);
				pj.pageDialog(aset);
				if(pj.printDialog(aset)) {
					System.out.println("selected printer " + service.getName());
					pj.print(aset);
				}
			} catch (PrinterException pe) { 
				System.err.println(pe);
			}
		}
	}

	public int print(Graphics g,PageFormat pf,int pageIndex) {

		if (pageIndex == 0) {
			Graphics2D g2d= (Graphics2D)g;
			g2d.drawString("X", 250, 250);
			//g2d.fillRect(0, 0, 200, 200);
			return Printable.PAGE_EXISTS;					
		} else {
			return Printable.NO_SUCH_PAGE;
		}
	}
	

}
